#include <unordered_map>
#include <vector>

using namespace std;

class Solution {
private:
    int gcp(int x, int y) {
        return x == 0 ? y : gcp(y % x, x);
    }
public:
    bool hasGroupsSizeX(vector<int>& deck) {
        map<int, int> count_map;
        for (int& item : deck) {
            count_map[item]++;
        }
        int g = -1;
        for (auto& item : count_map) {
            if (g == -1) {
                g = item.second;
            } else {
                g = gcp(g, item.second);
            }
        }
        return g >= 2;
    }
};

